package top.ucat.boots.starter.oauth2.server.auto;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import top.ucat.boots.starter.oauth2.client.realm.AuthorizingRealm;
import top.ucat.boots.starter.oauth2.client.service.api.ClientService;
import top.ucat.boots.starter.oauth2.client.service.api.TokenService;
import top.ucat.boots.starter.oauth2.server.dao.OauthUserCredentialsDao;
import top.ucat.boots.starter.oauth2.server.factory.DefaultLoginFactory;
import top.ucat.boots.starter.oauth2.server.factory.ScanQRSsoFactory;
import top.ucat.boots.starter.oauth2.server.factory.PhoneVerificationCodeSsoFactory;

/**
 * @Auther: Jun
 * @Date: 2019/9/4 11:01
 * @Description:
 */
public class OauthAutoConfigure {

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private OauthUserCredentialsDao oauthUserCredentialsDao;
    @Autowired
    private AuthorizingRealm authorizingRealm;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private ClientService clientService;

    @Bean
    public DefaultLoginFactory getDefaultLoginFactory() {
        DefaultLoginFactory instance = DefaultLoginFactory.getInstance(redisTemplate, oauthUserCredentialsDao);
        instance.setAuthorizingRealm(authorizingRealm);
        instance.setClientService(clientService);
        instance.setTokenService(tokenService);
        return instance;
    }

    @Bean
    public ScanQRSsoFactory getScanQRSsoFactory() {
        ScanQRSsoFactory instance = ScanQRSsoFactory.getInstance(getDefaultLoginFactory());
        instance.setAuthorizingRealm(authorizingRealm);
        instance.setClientService(clientService);
        instance.setTokenService(tokenService);
        return instance;
    }

    @Bean
    public PhoneVerificationCodeSsoFactory getPhoneVerificationCodeSsoFactory() {
        PhoneVerificationCodeSsoFactory instance = PhoneVerificationCodeSsoFactory.getInstance(getDefaultLoginFactory());
        instance.setAuthorizingRealm(authorizingRealm);
        instance.setClientService(clientService);
        instance.setTokenService(tokenService);
        return instance;
    }


}
